package com.dx.security.dto;

import com.dx.entity.user.Role;
import com.dx.entity.user.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @author : Yu.Tan
 * @date : 2023/7/22 18:40
 * @desc : this class for xxxxx
 **/
@Data
public class UserDetailDTO implements Serializable, UserDetails {

    private User user;

    private List<Role> roles;

    private List<String> roleCodes;



    private Collection<? extends GrantedAuthority> grantedAuthorities;


    public Long getUserId() {
        return this.user.getId();
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return this.getUser().getPassword();
    }

    @Override
    public String getUsername() {
        return this.getUser().getUserName();
    }

    /**
     * 账户是否没过期
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账户是否没被锁定
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 账户凭据是否没过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 账户是否启用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
